<?php

namespace app\common\model\mysql;

use think\Model;

class SRubikImg extends Model
{
    //批量插入魔方与魔方图片关联表数据
    public function insertAllSRubikImg($datas,$rubikId,$order_num=0){
        $data = [];
        foreach ($datas as $categoryId) {
            $order_num++;
            $data[] = [
                'rubik_img_url' => $categoryId['imgUrl'],
                'rubik_id' => $rubikId,
                'rubik_link' => $categoryId['url'],
                'order_num'=>$order_num,
            ];
        }
        return $this->insertAll($data);
    }

    //获取魔方图片数据
    public function getRubikImg($rubikId,$field = '*'){
        $order = [
            "order_num" =>"asc",
        ];
        $where = [
            ['rubik_id', '=', $rubikId]
        ];
        $result = $this->where($where)->order($order)->field($field)->select();
        return $result->toArray();
    }

    /**
     * 删除魔方与魔方图片数据信息
     * @param $ids
     * @return bool
     */
    public function deleteRubikImgIds($id){
        if(empty($id)){
            return false;
        }
        $where = [
            ['rubik_id', '=', $id]
        ];
        $result = $this->where($where)->delete();
        return $result;
    }
}
